import { http } from "@/utils/http";
import type { HttpResponse } from "types/request";
import { URL_PREFIX } from "./constants";
import type {
  TradeEnabledAppInfo,
  ManualPreflightCheckRequest,
  ManualPreflightCheckResponse,
  ManualOrderRequest
} from "@/types/trade.types";

/** 获取可用的交易账号应用列表 */
export const getTradeEnabledApps = () => {
  return http.request<HttpResponse<TradeEnabledAppInfo[]>>(
    "get",
    `${URL_PREFIX}/trade/apps`
  );
};

/** 手动交易预检接口：订阅行情、校验交易上下文并返回一次性令牌 */
export const manualPreflightCheck = (data: ManualPreflightCheckRequest) => {
  return http.request<HttpResponse<ManualPreflightCheckResponse>>(
    "post",
    `${URL_PREFIX}/trade/manual/preflight`,
    { data }
  );
};

/** 手动下单接口 */
export const manualPlaceOrder = (data: ManualOrderRequest) => {
  return http.request<HttpResponse<string[]>>(
    "post",
    `${URL_PREFIX}/trade/manual/order`,
    { data }
  );
};

/** 撤单接口 */
export const cancelOrder = (trade_app_name: string, vt_order_id: string) => {
  return http.request<HttpResponse<string>>(
    "delete",
    `${URL_PREFIX}/trade/manual/order`,
    { params: { trade_app_name, vt_order_id } }
  );
};
